home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / kevoSource / global.h < prev    next >
Text File  |  1993-05-13  |  7KB  |  269 lines

  1. /* Kevo -- a prototype-based object-oriented language */
  2. /* (c) Antero Taivalsaari 1991-1993                   */
  3. /* Some parts (c) Antero Taivalsaari 1986-1988           */
  4. /* Global.h: Global definitions and data areas          */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <ctype.h>
  10. #include <signal.h>
  11. #include <setjmp.h>
  12. #include <time.h>
  13.  
  14.  
  15. /* For portability (we want int's to be at least 32 bits long) */
  16. /*
  17.   #define  int        long
  18.   #define  unsigned    unsigned long
  19. */
  20.  
  21.  
  22. /* Include portable header files */
  23.  
  24. #include "memory.h"
  25. #include "lists.h"
  26. #include "context.h"
  27. #include "family.h"
  28. #include "recompile.h"
  29. #include "tasks.h"
  30. #include "files.h"
  31. #include "keybuf.h"
  32. #include "signals.h"
  33. #include "debug.h"
  34. #include "kernel.h"
  35. #include "image.h"
  36. #include "prim.h"
  37.  
  38. #include "blockfiles.h"
  39.  
  40. /* Global compile-time constants */
  41.  
  42. #undef     TRUE
  43. #undef     FALSE
  44.  
  45. #define  TRUE         -1L 
  46. #define  FALSE        0L 
  47. #define  NIL        0L
  48.  
  49. /* CELL should be 'sizeof(int)' */
  50. #define  CELL        4
  51.  
  52. #define     BS            8
  53. #define     TAB        9
  54. #define     LF            10
  55. #define  CR            13
  56. #define     BL            32
  57.  
  58.  
  59. /* Root contexts (name spaces) */
  60.  
  61. /* 'rootContext' holds the names of all the system definitions */
  62. /* 'userContext' is the root for user-given definitions */
  63. /* 'lastContext' refers to the latest defined context in the system */
  64.  
  65. extern   CONTEXT*    rootContext;
  66. extern   CONTEXT*    userContext;
  67. extern     CONTEXT*    lastContext;
  68. extern     CONTEXT*    dummyContext;
  69.  
  70.  
  71. /* Name (pair) flags */
  72.  
  73. #define    ImmedFlag    0x80
  74. #define SmudgeFlag    0x40
  75. #define HiddenFlag    0x08
  76.  
  77.  
  78. /* References to the three execution stacks */
  79. /* Note that in the current implementation stacks grow upwards so */
  80. /* as to allow them to be resized at runtime simply using 'realloc' */
  81.  
  82. /* The amount of additional items at the bottom of each stack */
  83. /* (reserved to avoid crashes resulting from stack manipulation errors */
  84.  
  85. #define    UNDERFLOWRESERVE    4
  86.  
  87.  
  88. /* Data stack */
  89. extern     int*            dataSp;   
  90.  
  91. #define  topData        (*dataSp)
  92. #define  secondData        (*(dataSp-1))
  93. #define  thirdData        (*(dataSp-2))
  94. #define  fourthData        (*(dataSp-3))
  95.  
  96.  
  97. /* Return stack */
  98. extern   int**            returnSp; 
  99.  
  100. #define  topReturn        (*returnSp)
  101. #define  secondReturn    (*(returnSp-1))
  102. #define  thirdReturn    (*(returnSp-2))
  103. #define  fourthReturn    (*(returnSp-3))
  104.  
  105.  
  106. /* Context stack */
  107. extern   int**            contextSp; 
  108.  
  109. #define     topContext        (*contextSp)
  110. #define  secondContext    (*(contextSp-1))
  111. #define  prevContext    (*(contextSp+1))
  112. #define     CWD            (*(contextStackBottom()+1))
  113.  
  114.  
  115. /* The most frequently called functions are "inlined" here */
  116.  
  117. #define        popData()            (*dataSp--)
  118. #define        nPopData(n)            dataSp -= (n)
  119. #define     pushData(data)        *++dataSp = (data)
  120. #define        nPushData(n)        dataSp += (n)
  121.  
  122. #define     popReturn()            (*returnSp--)
  123. #define        nPopReturn(n)        returnSp -= (n)
  124. #define        pushReturn(addr)     *++returnSp = (addr)
  125. #define        nPushReturn(n)        returnSp += (n)
  126.  
  127. #define        popContext()        (*contextSp--)
  128. #define        pushContext(addr)    *++contextSp = (addr)
  129.  
  130.  
  131. /* DATAOFFSET tells how many extra cells each instance has */
  132. /* before their actual data area starts. In the current implementation, */
  133. /* The first two cells contain the '(=context)' operation and the address */
  134. /* to the context itself (the dictionary/name space) */
  135.  
  136. #define DATAOFFSET    2
  137.  
  138.  
  139. /* Execution pointers */
  140.  
  141. extern     TASK**        up;        /* Current task pointer */
  142. extern     OBJECT*    op;        /* Previous object pointer */
  143. extern     int**        ip;        /* Instruction pointer */
  144.  
  145.  
  146. /* Environment buffers for 'setjmp' */
  147.  
  148. extern    jmp_buf    p_inner;    /* Preemptive inner interpreter jump buffer for longjmp */
  149. extern    jmp_buf c_inner;    /* Cooperative  - " - */
  150. extern    jmp_buf    debug;        /* Debugger longjump buffer */
  151.  
  152.  
  153. /* Multitasking modes and variables */
  154.  
  155. #define    PREEMPTIVE      0
  156. #define COOPERATIVE     1
  157.  
  158. extern    int        supervisor;        /* Are we currently in the supervisor mode */
  159.  
  160. extern    int        multitasking;    /* Is task switching allowed? */
  161. extern    int        mtaskMode;        /* Either PREEMPTIVE or COOPERATIVE */
  162.  
  163. extern    int        slice;            /* Time slice counter */
  164. extern    int        basePriority;    /* Base priority of newly created tasks */
  165.  
  166. extern TASK**    firstTask;        /* The first defined task in the system */
  167. extern TASK**     latestTask;        /* The latest defined task in the system */
  168.  
  169. extern int        taskCount;        /* How many tasks there are in total */
  170. extern int        runningCount;    /* How many of them are running */
  171.  
  172.  
  173. /* Critical region variables (see <| and |> in prim.c) */
  174.  
  175. extern int        inProtRegion;    /* Level of nested protected regions */
  176. extern int         mtStore;        /* temporary store for 'multitasking' */
  177.  
  178.  
  179. /* Tracing variables and states */
  180.  
  181. extern    int            traceMode;    /* Current tracing mode */
  182.  
  183. #define    NOTRACE        0
  184. #define TRACE        1
  185. #define FULLTRACE    2
  186. #define QUITTRACE    -1
  187.  
  188.  
  189. /* Debugger variables */
  190.                                 /* Needed in 'debugExit' and 'resume' */
  191. extern  TASK**        debugTask;    /* The task which invoked debugging */
  192. extern    int**        rpStore;    /* Return stack pointer temporary store */
  193.  
  194.  
  195. /* Macros to standard files */
  196. /* Each task has its own file stacks, so these are pretty complicated */
  197.  
  198. #define infileStk    ((int*)((*up)->infileStack->mfa))
  199. #define infileSSize    ((*up)->infileStack->sfa)
  200. #define infileSp    ((*up)->infilePtr)
  201. #define infile        ((*up)->infile)
  202.  
  203. #define outfileStk    ((int*)((*up)->outfileStack->mfa))
  204. #define outfileSSize ((*up)->outfileStack->sfa)
  205. #define outfileSp    ((*up)->outfilePtr)
  206. #define outfile        ((*up)->outfile)
  207.  
  208. #define errfile        ((*up)->errfile)
  209.  
  210. extern    FILE*    confile;    /* Console file */
  211. extern    FILE*   imgfile;    /* Image (boot) file */
  212.  
  213.  
  214. /* String management buffer for several operations in 'port.c' */
  215.  
  216. #define CHARBUFLEN    256
  217. extern     char    charbuffer[];
  218.  
  219.  
  220. /* Propagation modes */
  221. /* Needed in determining how widely dynamic changes should be propagated */
  222. #define THIS_ONLY    1
  223. #define WHOLE_FAMILY 2
  224. #define DERIVATIVES    3
  225.  
  226.  
  227. /* Modification modes */
  228. /* Needed in clone family migration */
  229. #define ADDING_SOMETHING        1
  230. #define RENAMING_SOMETHING        2
  231. #define REDEFINING_SOMETHING    3
  232. #define REMOVING_SOMETHING        4
  233. #define PASTING_SOMETHING        5
  234. #define ENCAPSULATING_SOMETHING 6
  235.  
  236.  
  237. /* Global references to certain primitives */
  238.  
  239. /* Initialized in 'prim.c' */
  240. extern    OBJECT*    oExit;
  241. extern    OBJECT*    oLit;
  242. extern    OBJECT*    oStrLit;
  243. extern    OBJECT*    oContext;
  244. extern    OBJECT* oSharedVar;
  245. extern    OBJECT* oTaskVar;
  246. extern    OBJECT* oSharedConst;
  247. extern    OBJECT* oTaskConst;
  248. extern    OBJECT* oREF;
  249. extern    OBJECT*    oVAR;
  250. extern    OBJECT*    oCONST;
  251.  
  252. /* Initialized in 'image.c' */
  253. extern    OBJECT* oBoot;
  254. extern    OBJECT* oShell;
  255. extern    OBJECT* oError;
  256. extern    OBJECT* oUserRoot;
  257.  
  258.  
  259.  
  260. /* Object kinds in object-oriented programming (needed mainly for the browser) */
  261.  
  262. #define UNKNOWN        1
  263. #define PRIMITIVE    2
  264. #define    REF            3
  265. #define VAR            4
  266. #define CONST        5
  267. #define METHOD        6
  268.  
  269.